package com.oocl.data.dataimport;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import com.oocl.dao.BooksDao;
import com.oocl.dao.impl.BooksDaoImpl;
import com.oocl.pojo.Books;

public class DataImport {
	private static BooksDao booksDao ;
	
	static{
		booksDao = new BooksDaoImpl();
	} 
	
    public static void importData() {
    	InputStream in =null;
    	ObjectInputStream i = null;
		try {
			in = new FileInputStream("data.txt");
			i = new ObjectInputStream(in);
			Object obj = null;
			List<Books> list = new ArrayList<Books>();
		    while((obj = i.readObject())!=null){
			   Books book = (Books) obj;
			   list.add(book);
		    }
		    booksDao.addBooks(list,2000);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}catch (IOException e) {
		}finally{
			try {
				i.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
    	
    	
    }
}
